

########################################################################################
# account manager
# - a simple account manager
# -
########################################################################################
class AccountManager:
  def __init__(self):
    self._account_status_dict = {}

  def get_account_status(self, owner='ALL'):
    return self._account_status_dict

  def on_account_info(self, account_info):
    meo = "{}:{}:{}".format(account_info.market, account_info.exchange, account_info.owner)
    if meo not in self._account_status_dict.keys():
      self._account_status_dict[meo] = {}
    acc = self._account_status_dict[meo]
    # balance
    if 'each_balance' in account_info.account_balance:
      bal = []
      for item in account_info.account_balance['each_balance']:
        currency = item['currency']
        total = item['total']
        bal.append((currency, total))
      acc['balance'] = bal
    # position
    if 'each_position' in account_info.account_position:
      pos = []
      for item in account_info.account_position['each_position']:
        symbol = item['symbol']
        net_pos = item['net_position']
        pos.append((symbol, net_pos))
      acc['position'] = pos
    #print(self._account_status_dict)
